import { _decorator } from 'cc';
import { BaseView } from '../../../../scripts/libs/rxjs/cc3/BaseView';
import { Sprite, Label } from 'cc';
import { MergeASAP } from '../../../../scripts/libs/rxjs/cc3/Merge';
import { ReactiveProperty } from '../../../../scripts/libs/rxjs/cc3/ReactiveProperty';
import { color } from 'cc';
const { ccclass, property, executeInEditMode } = _decorator;

@ccclass('EditorGround')
@executeInEditMode
export class EditorGround extends BaseView {

    posId = ReactiveProperty.Create<number>(null);

    isWall = ReactiveProperty.Create<boolean>(null);

    @property(Label)
    infoLabel: Label = null;

    useObserves() {
        return [
            MergeASAP(this.posId, this.isWall).subscribe(this.refresh.bind(this)),
        ];
    }

    refresh() {
        if (this.isWall.value) {
            this.getComponent(Sprite).color = color().fromHEX('888888');
        } else {
            this.getComponent(Sprite).color = color().fromHEX('b1b1b1');
        }
        this.infoLabel.string = `${this.posId.value}`;
    }

}

